package com.ihr360.payroll.dao;

import com.ihr360.payroll.model.dto.salary.task.period.ActivePayPeriod;
import com.ihr360.rest.reposity.SimpleRestReposity;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.Collection;
import java.util.List;

public interface ActivePayPeriodRepository extends SimpleRestReposity<ActivePayPeriod, Long> {
    @Query(value = "SELECT count(1) FROM activepayperiod where companyId=? and salaryPlan_id=? and `year`=? and `month` =?", nativeQuery = true)
    int countByPlanIdAndYearAndMonth(String companyId, Long salaryPlan, int year, int month);


    @Query(value = "select salaryPlan_id from activepayperiod where id=?", nativeQuery = true)
    Long querySalaryPlanId(Long id);

    List<ActivePayPeriod> findAllByCompanyIdAndSalaryPlanIdIn(String companyId, Collection<Long> salaryPlanIds);

    int countByCompanyIdAndSalaryPlanId(String companyId, Long salaryPlanId);

    List<ActivePayPeriod> findAllByCompanyId(String companyId);

    List<ActivePayPeriod> findByCompanyIdAndApplicationIdIn(String companyId, List<String> applicationIdList);

    ActivePayPeriod findByCompanyIdAndApplicationId(String companyId, String applicationId);

    List<ActivePayPeriod> findAllByCompanyIdAndSalaryPlanId(String companyId, Long salaryPlanId);

    List<ActivePayPeriod> findAllByCompanyIdAndSalaryPlanAttendancePlanId(String companyId, Long attendancePlanId);

    List<ActivePayPeriod> findAllByCompanyIdAndSalaryPlanPayrollConfigId(String companyId, Long payrollConfigId);
}